package cn.marinda.spritefragment.commands;

import cn.marinda.spritefragment.SpriteFragment;
import cn.marinda.spritefragment.data.ConfigManager;
import cn.marinda.spritefragment.util.PlayerUtil;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;


public class Command implements CommandExecutor {
        /*
        命令区域
         */
    private ConfigManager gm = null;
    @Override
    public boolean onCommand(CommandSender sender, org.bukkit.command.Command cmd, String label, String[] args) {
        if(sender instanceof Player){
            Player p = (Player)sender;
            if(args.length == 1){
                CommandsObject obj = new GuiCommand();
                if(args[0].equalsIgnoreCase("on")){
                    obj.registerCommands(args[0],args);
                    gm = new ConfigManager();
                    p.openInventory(cn.lovelycatv.custom.GUI.SynthesisGUI.getSynthesisGUI(gm.getConfigData().getInvName()));
                    return true;
                }
            }
            if(args.length ==4){
                if(args[0].equalsIgnoreCase("give")){
                    CommandsObject obj = new GiveCommand();
                    obj.registerCommands(args[0],args);
                    return true;
                }
                if(args[0].equalsIgnoreCase("result")){
                    CommandsObject result = new ResultCommand();
                    result.registerCommands(args[0],args);
                        return true;
                }
            }
            help(p);
            return true;
        }
        SpriteFragment.plugin.getServer().getConsoleSender().sendMessage("§c控制台不允许使用命令");
        return true;
    }
    public void help(Player p){
        gm = new ConfigManager();
        for(String help : gm.getMessageData().getHelp()){
            p.sendMessage(help);
        }
    }
}
